home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / msj / v07n03 / toolhelp.exe / INIT.C next >
Encoding:
C/C++ Source or Header  |  1992-05-01  |  5.3 KB  |  143 lines

  1. /*-------------------------------------------------------------*\
  2.  |  INIT.C  -- Initialization for TaskMstr.EXE.                |
  3. \*-------------------------------------------------------------*/
  4. #include <Windows.H>
  5. #include <WindowsX.H>
  6. #include <ToolHelp.H>
  7. #include <Memory.H>
  8. #include "TaskMstr.H"
  9.  
  10.  
  11. /*-------------------------------------------------------------*\
  12.  |                      Global Variables.                      |
  13. \*-------------------------------------------------------------*/
  14. extern APPCOLORS    ac;
  15. extern APPMETRICS   am;
  16. extern char       * achSegType[];
  17. extern HBRUSH       hbr1;
  18. extern HBRUSH       hbr2;
  19. extern HFONT        hfont;
  20.  
  21. /*-------------------------------------------------------------*\
  22.  |  trInitMetrics:  Initialize application specific metrics.   |
  23. \*-------------------------------------------------------------*/
  24. void FAR PASCAL trInitMetrics(HDC hdc)
  25.     {
  26.     DWORD       dwSize;
  27.     int         cb;
  28.     int         cxWidth;
  29.     LOGFONT     lf;
  30.     TEXTMETRIC  tm;
  31.  
  32.     // Set up application metric info.
  33.     //
  34.     GetTextMetrics (hdc, &tm);
  35.  
  36.     hfont = GetStockObject (SYSTEM_FONT);
  37.     GetObject (hfont, sizeof (LOGFONT), &lf);
  38.     lf.lfHeight         = MulDiv (lf.lfHeight, 7, 8);
  39.     lf.lfWidth          = 0;
  40.     lf.lfWeight         = 700;
  41.     lf.lfQuality        = DEFAULT_QUALITY;
  42.     lf.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
  43.     lf.lfFaceName[0]    = '\0';
  44.     hfont = CreateFontIndirect (&lf);
  45.  
  46.     SelectObject (hdc, hfont);
  47.  
  48.     am.sm_cxBorder = GetSystemMetrics (SM_CXBORDER);
  49.     am.sm_cyBorder = GetSystemMetrics (SM_CYBORDER);
  50.     am.tx_cyLine   = tm.tmHeight +
  51.                      tm.tmExternalLeading +
  52.                      tm.tmInternalLeading;
  53.  
  54.     am.tx_xMargin  = tm.tmAveCharWidth / 2;
  55.     am.tx_yMargin  = tm.tmExternalLeading;
  56.  
  57.     am.lbTask_cyHeight   = am.tx_cyLine * 4;     // 4 lines in listbox
  58.     am.lbModule_cyHeight = am.tx_cyLine +
  59.                            am.tx_cyLine / 2;     // 1.5 lines in listbox
  60.  
  61.     am.bar_cyHeight = am.tx_cyLine + am.tx_cyLine / 2;
  62.  
  63.     am.xIcon = am.tx_xMargin + tm.tmAveCharWidth * 4;;
  64.     am.yIcon = ( (am.lbTask_cyHeight+am.tx_cyLine) / 2) -
  65.                ( GetSystemMetrics (SM_CYICON)  / 2);
  66.  
  67.     am.tx_xIconMargin = am.xIcon + tm.tmAveCharWidth * 2 +
  68.                         GetSystemMetrics (SM_CXICON);
  69.  
  70.     // Get width of longest 'task list' char string.
  71.     cb = lstrlen(achSegType[GT_UNKNOWN]);
  72.     dwSize = GetTextExtent (hdc, achSegType[GT_UNKNOWN], cb);
  73.     cxWidth = LOWORD (dwSize);
  74.  
  75.     // Create right-alignment offsets for task list.
  76.     am.tx_xTaskText = am.tx_xIconMargin + cxWidth;
  77.     am.tx_yTaskText = am.tx_cyLine + am.tx_yMargin;
  78.  
  79.     // Get width of longest 'module list' char string.
  80.     cb = lstrlen (achSegType[GT_BURGERMASTER]);
  81.     dwSize = GetTextExtent (hdc, achSegType[GT_BURGERMASTER], cb);
  82.     cxWidth = LOWORD (dwSize);
  83.  
  84.     // Create right-alignment offsets for module list.
  85.     am.tx_xModuleText = cxWidth;
  86.     am.tx_yModuleText = am.lbModule_cyHeight / 2 +
  87.                         tm.tmHeight / 4;
  88.  
  89.     // Calculate minimum tracking size for the main window.
  90.     am.win_xMinTracking = 2 * GetSystemMetrics (SM_CXFRAME)   +
  91.                           2 * GetSystemMetrics (SM_CYVSCROLL) +
  92.                           2 * am.tx_xTaskText                 +
  93.                               MulDiv (am.tx_xModuleText, 3, 2);
  94.     am.win_yMinTracking = 2 * GetSystemMetrics (SM_CYFRAME)   +
  95.                               GetSystemMetrics (SM_CYCAPTION) +
  96.                               am.lbTask_cyHeight - 1;
  97.  
  98.     am.win_cxInit       = am.win_xMinTracking;
  99.     am.win_cyInit       = 2 * GetSystemMetrics (SM_CYFRAME)   +
  100.                               GetSystemMetrics (SM_CYCAPTION) +
  101.                           SEGTYPE_COUNT * am.lbModule_cyHeight - 1;
  102.     }
  103.  
  104.  
  105. /*-------------------------------------------------------------*\
  106.  |    trInitColors:  Initialize table of application colors.   |
  107. \*-------------------------------------------------------------*/
  108. void FAR PASCAL trInitColors()
  109.     {
  110.     int iColor;
  111.  
  112.     // Set up color independent values.
  113.     ac.rgbForeSelect = GetSysColor (COLOR_HIGHLIGHTTEXT);
  114.     ac.rgbBackSelect = GetSysColor (COLOR_HIGHLIGHT);
  115.     ac.rgbBlack      = RGB (0, 0, 0);
  116.  
  117.     // Set up for monochrome devices.
  118.     //
  119.     if (ac.cColors == 2)
  120.         {
  121.         for (iColor = 0; iColor < 10; iColor++)
  122.             {
  123.             ac.rgbSolidColors[iColor] = ac.rgbBlack;
  124.             }
  125.         hbr1 = CreateHatchBrush (HS_DIAGCROSS, RGB (0, 0, 0));
  126.         hbr2 = CreateHatchBrush (HS_FDIAGONAL, RGB (0, 0, 0));
  127.         }
  128.     else   // Color devices.
  129.            //
  130.         {
  131.         ac.rgbSolidColors[GT_UNKNOWN ] = RGB (255,   0,   0);
  132.         ac.rgbSolidColors[GT_DGROUP  ] = RGB (  0,   0, 255);
  133.         ac.rgbSolidColors[GT_DATA    ] = RGB (  0,   0,   0);
  134.         ac.rgbSolidColors[GT_CODE    ] = RGB (  0, 128,   0);
  135.         ac.rgbSolidColors[GT_TASK    ] = RGB (128,   0,   0);
  136.         ac.rgbSolidColors[GT_RESOURCE] = RGB (  0,   0, 128);
  137.         ac.rgbSolidColors[GT_MODULE  ] = RGB (128, 128, 128);
  138.  
  139.         hbr1 = CreateSolidBrush (ac.rgbSolidColors[GT_UNKNOWN]);
  140.         hbr2 = CreateSolidBrush (ac.rgbSolidColors[GT_DGROUP]);
  141.         }
  142.     }
  143.